import { defineStore } from 'pinia';

const useStore = defineStore('store', {
  persist: {
    enabled: true,
    /* strategies: [
        { storage: sessionStorage, paths: ['firstName', 'lastName'] }, // firstName 和 lastName字段用sessionStorage存储
        { storage: localStorage, paths: ['accessToken'] }, // accessToken字段用 localstorage存储
    ], */
  },
  state: () => ({
    chats: {
      chatType: "1",
      stream: true,
      jsonFormat: false,
      temperature: 7,
      topK: 0,
      topP: 7.5,
      sourceType: "1",
      cacheLimit: 6,
      cnAnswer: true,
      model: "",
      similarityScore: 7,
      result: "",
      filename: "",
      flowId: "",
      mode: "1",
      pptTemplate: "",
      pageSize: 10,
      uploadFileId: "",
    },
    api: "",
    buttonProxy: "/system",
    queryData: {},
    pages: {},
    page: { page: 1, size: 10 },
    loginFlag: false,
    loginInfo: null,
    dicts: [],
    buttons: [],
    menus: {
      menuId: "",
      data: [],
      siderCollapsed: false,
      current: "",
      title: "",
      subTitle: "",
      searchData: [],
      cache: [],
    },
    forms: {
      see: false,
      action: ""
    }
  }),
  getters: {

  },
  actions: {
    setResult(v) {
      this.chats.result = v;
    },
    addResult(v) {
      this.chats.result += v;
    },
    setChats(v) {
      this.chats = v;
    },
    setApi(v) {
      this.api = v;
    },
    setCurrent(v) {
      this.menus.current = v;
    },
    setMenuId(v) {
      this.menus.menuId = v;
    },
    setSiderCollapsed() {
      this.menus.siderCollapsed = !this.menus.siderCollapsed;
    },
    setTitle(v) {
      this.menus.title = v;
    },
    setSubTitle(v) {
      this.menus.subTitle = v;
    },
    setLoginInfo(v) {
      this.loginInfo = v;
    },
    setButtons(v) {
      this.buttons = v;
    },
    setLoginFlag(v) {
      this.loginFlag = v;
    },
    setSee(v) {
      this.forms.see = v;
    },
    setAction(v) {
      this.forms.action = v;
    },
    setLoginInfo(v) {
      this.loginInfo = v;
    },
    setMenuData(v) {
      this.menus.data = v;
    },
    setMenuData(v) {
      this.menus.data = v;
    },
    setSearchData(v) {
      this.menus.searchData = v;
    },
    setQueryData(v) {
      this.queryData[this.menus.current] = v;
    },
    setMenuCache(v) {
      if (!this.menus.cache) {
        this.menus.cache = new Array();
      }
      let idx = this.menus.cache.findIndex(item => item.url == v.url);
      if (idx == -1) {
        if (this.menus.cache.length >= 10) {
          this.menus.cache.splice(0, 1);
        }
        this.menus.cache.push(v);
      }
    }
  }
})
export default useStore